package org.cid54.jshopper.dao.impl;

import java.util.List;
import org.cid54.jshopper.dao.ShopItemDao;
import org.cid54.jshopper.model.Item;
import org.cid54.jshopper.model.ShopItem;
import org.cid54.jshopper.model.ShoppingList;
import org.cid54.jshopper.model.UserGroup;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 *
 * @author fgo
 */
@Repository
public class ShopItemDaoImpl extends SuperEntityDaoImpl<ShopItem> implements ShopItemDao{

    @Override
    protected Class getEntityClass() {
        return ShopItem.class;
    }

    @Override
    public ShopItem findByName(String shopItemName) {
        Criteria criteria = this.getNewCriteria();

        criteria.add(Restrictions.eq("name", shopItemName));

        return (ShopItem) criteria.uniqueResult();
    }

    @Override
    protected boolean isSortableByName() {
        return false;
    }

    @Override
    public List<ShopItem> findByItem(Item item) {
        Criteria criteria = this.getNewCriteria();

        criteria.add(Restrictions.eq("item", item));

        return criteria.list();
    }

    @Override
    public ShopItem findByItemAndShoppingList(Item item, ShoppingList shoppingList) {

        Criteria criteria = this.getNewCriteria();

        criteria.add(Restrictions.eq("item", item));
        criteria.add(Restrictions.eq("shoppingList", shoppingList));

        return (ShopItem) criteria.uniqueResult();

    }

}
